package io2.nio.pipeline2;

public class HandlerContext {

    private Handler handler;
    private HandlerContext next;
    private HandlerContext prev;

    public HandlerContext(Handler handler) {
        this.handler = handler;
    }

    private void doRead(String obj) {
        this.handler.read(this, obj);
    }

    private void doWrite(String obj) {
        this.handler.write(this, obj);
    }

    public void read(HandlerContext next, String obj) {
        if(next != null)
            next.doRead(obj);
    }

    public void read(String obj) {
        read(next, obj);
    }

    public void write(HandlerContext prev, String obj) {
        if(prev != null)
            prev.doWrite(obj);
    }

    public void write(String obj) {
        write(prev, obj);
    }

    public void setNext(HandlerContext next) {
        this.next = next;
    }

    public void setPrev(HandlerContext prev) {
        this.prev = prev;
    }

    public HandlerContext getNext() {
        return next;
    }

    public HandlerContext getPrev() {
        return prev;
    }
}
